package com.medvalley.tcm.controller.admin.controller;

import com.medvalley.tcm.base.Result;
import com.medvalley.tcm.controller.BaseController;
import com.medvalley.tcm.controller.admin.service.OrgService;
import com.medvalley.tcm.controller.admin.vo.inputvo.OrgInputVo;
import com.medvalley.tcm.controller.admin.vo.inputvo.SearchOrgInputVo;
import com.medvalley.tcm.controller.admin.vo.outputvo.OrgOutputVo;
import com.medvalley.tcm.controller.admin.vo.outputvo.PageDataOutputVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author linsong
 * @date 2019/6/20 11:23
 **/
@RestController
@RequestMapping("/admin/org")
@Api(value = "PC端报告相关接口")
public class OrganizationController extends BaseController {

    @Autowired
    private OrgService orgService;

    @RequestMapping(value = "/search", method = RequestMethod.POST)
    @ApiOperation("搜索机构")
    public Result searchOrg(@ModelAttribute SearchOrgInputVo searchOrgInputVo) {
        PageDataOutputVo<OrgOutputVo> pageDataOutputVo = orgService.listOrg(searchOrgInputVo);
        return success(pageDataOutputVo);
    }

    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    @ApiOperation("删除机构")
    public Result deleteOrg(@RequestParam int id) {
        orgService.deleteOrg(id);
        return success();
    }

    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @ApiOperation("机构详情")
    public Result orgDetail(@RequestParam int id) {
        OrgOutputVo orgOutputVo = orgService.orgDetail(id);
        return success(orgOutputVo);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation("更新机构")
    public Result updateOrg(@ModelAttribute OrgInputVo orgInputVo) {
        orgService.updateOrg(orgInputVo);
        return success();
    }

}
